// ChildFrm.h : interface of the CChildFrame class
//


#pragma once

#include "ChildView.h"
#include "BasicFunction.h"
#include "ImageRetrieval.h"
#include "CrossNet.h"
#include "AnnotationTool.h"
#include "ImageClustering.h"
#include "CrossModalDialog.h"

class CChildFrame : public CMDIChildWnd
{
	DECLARE_DYNCREATE(CChildFrame)
public:
	CChildFrame();

// Attributes

// Operations
public:

// Overrides
	public:
	virtual BOOL	PreCreateWindow(CREATESTRUCT& cs);
	virtual BOOL	OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);

// Implementation
public:
	// view for the client area of the frame.
	CStringA		m_ColourInfo;
	CChildView		m_wndView;
	CRect			m_ChildFrameSize;
	CImageRetrieval*	m_ImageRetrieval;
	CAnnotationTool*	m_ManualAnnotation;
	CImageClustering*	imageclustering;
	CCrossModalDialog* crossmodaldialog;
	virtual ~CChildFrame();

protected:	//statusbar
	CStatusBar m_wndStatusBar;

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
protected:
	afx_msg void	OnFileClose();
	afx_msg void	OnSetFocus(CWnd* pOldWnd);
	afx_msg int		OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void	OnUpdatePane(CCmdUI* pCmdUI);
	DECLARE_MESSAGE_MAP()

private:
	//text attributes
	char**			word_compound;				//words
	int*			compound_index;				//compound index
	int*			corpus_word_num;			//number of char in each word
	int*			compound_id;				//ID of the compound words
	//!!!!!important!!!!!! reduce the compound_num by 1, which contain the frequency
	int*			compound_num;				//number of word in each compound
	int*			compound_frequency;			//frequency of each compound
	int*			division_num;				//number of compounds in each division
	int				corpus_num;					//number of words
	double			division_frequency;			//sum of log frequency in each compound division
	int				num_division;				//number of divisions
	int				compound_total;				//number of compound words
	bool			is_corpus_set;				//flag for index is set or not

public:
	//cross modal
	CCrossNet*		m_CrossNet;					//a cross-modal system
	//basic operation
	CBasicFunction	bf;

public:
//functions for image processing
	//test function
	void			OnTest(void);
	//image open and save
	void			OnImageOpen(void);
	void			OnImageSave(void);
	//image filter
	void			OnMedianFilter(void);
	void			OnLawFilter(void);
	//thresholding
	void			OnOtsu2d(void);
	void			OnOtsu1d(void);
	void			OnGraphic(void);
	//process image folder
	void			OnProcessFolder(void);
	//image segmentation using som
	void			OnImageSom(void);
	//feature extraction
	void			OnPixelFeature(void);
	void			OnZernikeMoment(void);
	//colour channel
	void			OnRedChannel(void);
	void			OnGreenChannel(void);
	void			OnBlueChannel(void);
	void			OnGrayChannel(void);
	//undo
	void			OnRecover(void);

public:
//function for text processing
	//set compound words corpus
	void			SetCorpus(void);
	//match keywords
	void			matchKeywords(void);
	//determine if a char is a legal char for words
	bool			isLetter(char c);
	//read words from a file
	bool			readWords(char* wfile, int flength, char** words, int* numChar, int NumWords);
	//count the number of words
	int				getWordCount(char* wfile, int flength);
	//match two char
	bool			matchChar(char* char1, char* char2, int charL);
	//get the number of compounds
	int				getCompoundNum(char* wfile, int flength);
	//get the index of compounds
	bool			getCompoundIndex(char* wfile, int flength, int* c_index, int* c_num);
	//get the compounds
	CString			getCompound(CString filename);
	//get the linguistic features
	double*			getLinguisticFeature(CString filename);
	//match compounds with corpus
	void			matchCompound(void);
	//destroy the corpus
	bool			DestroyCorpus(void);
	//merge text from several files
	void			TextMerge(void);
	//search back for a fullstop of the sentence
	int				BackwardStop(int curpos, char* m_source, int m_slen);
	//search forward for a fullstop of the sentence
	int				ForwardStop(int curpos, char* m_source, int m_slen);
	//extract figure caption and references
	void			CapRefExtraction(void);
	//search a index in the paper for caption or reference
	void			SearchCapRef(char* m_index, int m_ilen, char* m_source, int m_slen, char* m_cap,
					int* m_clen, char* m_ref, int* m_rlen);
	//search documents for terms frequency and inverse documents frequency
	void			OnTFTimesIDF(void);
	//Get the list of words from a set of files
	void			GetListOfWords(void);
	//Do the collocations
	void			Collocations(void);


public:
//basic operators
	CString			douTostr(double dou);
	bool			stringToFile(CString str);
	void			OnGenerateMatrix(void);

public:
//Image Annotation
	void			ImageAnnotation(void);
	void			ManualAnnotation(void);
//Get Image and Linguistic features for training and testing data set
	void			GetTrainingTesting(void);
//get the data dimension of the input file
	bool			GetDataDimension(char* f_input, int f_len, int* d_column, int* d_row);
//read the data to the matrix
	bool			ReadMatrixData(char* f_input, int f_len, int d_column, int d_row, double** m_data);
//get the linguistic feature from the files in a folder
	void			GetFolderLinguistic(void);
//Image clustering
	void			ImageClustering(void);

public:
//database operation
	void			OnLoadDatabase(void);
	void			OnImageRetrieval(void);
	void			OnLoadFulltext(void);

public:
	void			UpdateColourInfo(CStringA str);

public:
	void			OnLoadCrossModal(void);
	void			OnSaveCrossModal(void);
	void			OnCrossModalDialog(void);

	void			BootstrappingMultimodal(void);
	void			BootstrappingImages(void);
	
	void			ClusteringCompany(void);
};
